﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data.EntityClient;
using System.Data.SqlClient;

namespace PeapodCatcher
{
    static class Common
    {
        private static string _appDataPath;
        public static string AppDataPath
        {
            get
            {
                if (String.IsNullOrEmpty(_appDataPath))
                {
                    // Set the provider-specific connection string.
                    _appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PeapodCatcher");
                    DirectoryInfo di = new DirectoryInfo(_appDataPath);
                    if (!di.Exists)
                    {
                        di.Create();
                    }
                }
                return _appDataPath;
            }
        }

        private static string _databasePath;
        public static string DatabasePath
        {
            get
            {
                if (String.IsNullOrEmpty(_databasePath))
                {
                    // Set the provider-specific connection string.
                    _databasePath = Path.Combine(AppDataPath, "Data.sdf");
                }
                return _databasePath;
            }
        }

        private static string _connectionString;
        public static string ConnectionString
        {
            get
            {
                if (String.IsNullOrEmpty(_connectionString))
                {
                    _connectionString = String.Format("DataSource='{0}'", DatabasePath);
                }
                return _connectionString;
            }
        }


        public static string SafeFileName(string p) {
            string file = p;
            Array.ForEach(Path.GetInvalidFileNameChars(),
                  c => file = file.Replace(c.ToString(), String.Empty));
            return file;
        }
    }
}
